<?php


namespace App\Http\Controllers\Forwarder;


use App\Http\Controllers\Controller;
use App\Models\ForwarderComplain;
use Illuminate\Http\Request;

class ForwarderComplainController extends Controller
{
    public function index(Request $request)
    {
        $list = ForwarderComplain::where('forwarder_id', $request->user()->forwarder_id)->orderBy('status', 'asc')->orderBy('id', 'desc')->paginate();
        return $this->response($list);
    }

    public function store(Request $request, ForwarderComplain $obj)
    {
        $all = $request->all();
        $obj->fill($all);
        $obj->user_id = $request->user()->id;
        $obj->forwarder_id = $request->user()->forwarder_id;
        $obj->save();
        return $this->response();
    }

    public function update($id, Request $request)
    {
        $obj = ForwarderComplain::where('forwarder_id', $request->user()->forwarder_id)->where('id', $id)->first();
        $obj->update($request->all());
        return $this->response();
    }

}
